package hr.riteh.assistivecommunicator;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

public class CategoriesActivity extends Activity implements AdapterView.OnItemClickListener
{
	private Database mDatabase = new Database(this);

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);

		CategoriesAdapter adapter = new CategoriesAdapter(mDatabase.getCategories());

		GridView gridview = new GridView(this);
		gridview.setNumColumns(2);
		gridview.setAdapter(adapter);
		gridview.setOnItemClickListener(this);

		setContentView(gridview);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id)
	{
		mDatabase.increaseCategoryUsage(id);
		CategorySentencesActivity.start(this, id);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		getMenuInflater().inflate(R.menu.activity_categories, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		switch (item.getItemId())
		{
			case R.id.menuitem_import:
				startActivity(new Intent(this, ImportActivity.class));
				return true;
			default:
				return super.onOptionsItemSelected(item);
		}
	}
}
